package com.corpgovernment.organization.mapper;

import com.corpgovernment.api.organization.model.bookingrelation.BookingRange;
import com.corpgovernment.organization.common.mybatis.TkMapper;
import com.corpgovernment.organization.entity.db.MbFreshPassenger;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author wangyujue
 */
@Repository
public interface MbFreshPassengerMapper extends TkMapper<MbFreshPassenger> {


    List<MbFreshPassenger> listByOrgId(@Param("orgId") String orgId, @Param("uid") String uid, @Param("uids") List<String> uids, @Param("noEmployeeIds") List<Long> noEmployeeIds);

    List<MbFreshPassenger> listByOrgIds(@Param("orgIds") List<String> orgIds, @Param("uid") String uid,
                                        @Param("uids") List<String> uids,
                                        @Param("noEmployeeIds") List<Long> noEmployeeIds,
                                        @Param("currentUserOrgId") String currentUserOrgId);

    List<MbFreshPassenger> listByOrgIdsAndUid(@Param("orgIds") List<String> orgIds,
                                              @Param("uid") String uid, @Param("uids") List<String> uids,
                                              @Param("noEmployeeIds") List<Long> noEmployeeIds,
                                              @Param("currentUserOrgId") String currentUserOrgId);

    List<MbFreshPassenger> listByOrgIdAndName(@Param("orgId") String orgId, @Param("uid") String uid,  @Param("freshPassengerIds") List<Long> freshPassengerIds, @Param("uids") List<String> uids, @Param("noEmployeeIds") List<Long> noEmployeeIds);

    List<MbFreshPassenger> listByOrgIdsAndName(@Param("orgIds") List<String> orgIds, @Param("uid") String uid,
                                               @Param("freshPassengerIds") List<Long> freshPassengerIds, @Param("uids") List<String> uids,
                                               @Param("noEmployeeIds") List<Long> noEmployeeIds,
                                               @Param("currentUserOrgId") String currentUserOrgId);

    List<MbFreshPassenger> listByOrgIdsAndUidAndName(@Param("orgIds") List<String> orgIds, @Param("uid") String uid,
                                                     @Param("freshPassengerIds") List<Long> freshPassengerIds, @Param("uids") List<String> uids,
                                                     @Param("noEmployeeIds") List<Long> noEmployeeIds,
                                                     @Param("currentUserOrgId") String currentUserOrgId);

    List<MbFreshPassenger> listNonEmployeeByUid(@Param("uid") String uid, @Param("orgId") String orgId, @Param("noEmployeeIds") List<Long> noEmployeeIds, @Param("uids") List<String> uids, @Param("freshPassengerIds") List<Long> freshPassengerIds);

    int batchSave(@Param("needSaveFreshPassengerList") List<MbFreshPassenger> needSaveFreshPassengerList);

    /**
     * 批量禁用
     *
     * @param uids
     * @param orgId
     * @return
     */
    int batchUpdateValid(@Param("uids") List<String> uids, @Param("orgId") String orgId, @Param("valid") Integer valid);

    /**
     * 修改出行人账号有效性
     *
     * @param uid
     * @param accountValid
     * @return
     */
    int updateAccountValid(@Param("uid") String uid, @Param("accountValid") Integer accountValid);

    int freshEmployee(@Param("employeeUids") List<String> employeeUids);

	int freshNonEmployee(@Param("nonEmployeeUids") List<Long> nonEmployeeUids);

	int updateEmployeeOrg(@Param("mbFreshPassenger") MbFreshPassenger mbFreshPassenger);

	int batchUpdateEmployeeOrg(@Param("uids") List<String> uids, @Param("orgId") String orgId);

	int deleteEmployee(@Param("uid") String uid, @Param("orgId") String orgId);

	int deleteNonEmployee(@Param("nonEmployeeUid") Long nonEmployeeUid);

	/**
	 * 删除用户非员工
	 *
	 * @param uid
	 * @return
	 */
	int deleteNonEmployeeByUid(@Param("uid") String uid);

	List<MbFreshPassenger> queryAllName();

	/**
	 * 根据员工号查询
	 *
	 * @param employeeIds
	 * @return
	 */
	List<MbFreshPassenger> findByEmployeeIds(@Param("employeeIds") List<String> employeeIds);

	/**
	 * 根据非员工号查询
	 *
	 * @param nonEmployeeIds
	 * @return
	 */
	List<MbFreshPassenger> findByNonEmployeeIds(@Param("nonEmployeeIds") List<Long> nonEmployeeIds);

	/**
	 * 根据名称精确查询
	 *
	 * @param name
	 * @return
	 */
	List<Long> findByName(@Param("name") String name, @Param("needEmployee") boolean needEmployee);

    /**
     * 根据代订范围和出行人id查询
     *
     * @param bookingOrgIds
     * @param freshPassengerIds
     * @param uid
     * @param orgId
     * @return
     */
    List<MbFreshPassenger> selectByBookingOrgIdsAndFreshPassengerIds(@Param("bookingOrgIds") List<String> bookingOrgIds,
        @Param("bookingUsers") List<BookingRange.BookingUser> bookingUsers,
        @Param("freshPassengerIds") List<Long> freshPassengerIds, @Param("uid") String uid,
        @Param("orgId") String orgId);

	/**
	 * 根据员工查询出行人
	 *
	 * @param uid
	 * @param orgId
	 * @param freshPassengerIds
	 * @return
	 */
	List<MbFreshPassenger> selectByUidAndOrgIdAndFreshPassengerIds(@Param("uid") String uid, @Param("orgId") String orgId, @Param("freshPassengerIds") List<Long> freshPassengerIds);

	/**
	 * 根据员工查询出行人（不包含非员工）
	 *
	 * @param bookingOrgIds
	 * @param freshPassengerIds
	 * @return
	 */
	List<MbFreshPassenger> selectEmployeeByBookingOrgIdsAndFreshPassengerIds(@Param("bookingOrgIds") List<String> bookingOrgIds, @Param("bookingUsers") List<BookingRange.BookingUser> bookingUsers, @Param("freshPassengerIds") List<Long> freshPassengerIds, @Param("uid") String uid, @Param("orgId") String orgId);

	int deleteByUidAndOrgId(@Param("mbFreshPassengerList") List<MbFreshPassenger> mbFreshPassengerList);

    /**
     * 批量插入新鲜度数据
     * @param mbFreshPassengerList
     * @return
     */
	int updateBatchSelective(List<MbFreshPassenger> mbFreshPassengerList);

	List<MbFreshPassenger> listAllValidFreshPassengers();

	int updateEnNameBatch(List<MbFreshPassenger> mbFreshPassengerList);
}
